package de.iritgo.skillfull.entity.command;

import org.springframework.context.ApplicationContext;

import de.iritgo.skillfull.Left4Alien;
import de.iritgo.skillfull.component.visitor.PositionVisitor;
import de.iritgo.skillfull.entity.Command;
import de.iritgo.skillfull.entity.Entity;
import de.iritgo.skillfull.entity.EntityManager;

public class RemoveEntityCommand implements Command 
{
	private Entity entity;
	private boolean done;
	
	public RemoveEntityCommand (Entity entity)
	{
		this.entity = entity;
		done = false;
	}

	public String getName ()
	{
		return "RemoveEntity"; 
	}

	@Override
	public boolean canPerform () 
	{
		return true;
	}

	@Override
	public void perform (int delta) 
	{
		// Very bad!!
		ApplicationContext appContext = Left4Alien.getApplicationContext();
		EntityManager entityManager = (EntityManager) appContext.getBean ("de.iritgo.skillfull.EntityManager");
		entityManager.removeEntity (entity);

		done = true;
	}
	
	@Override
	public void stop() 
	{
		done = true;
	}

	public Command getUndoCommand () 
	{
		return null;
	}

	@Override
	public boolean isDone () 
	{
		return done;
	}
}
